package com.example.arithmeticleetcode.learnArithmetic.set.rbtree;


import com.example.arithmeticleetcode.learnArithmetic.twonodetree.Person;
import com.example.arithmeticleetcode.learnArithmetic.twonodetree.util.BinaryTrees;

import java.util.Comparator;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-08-25 18:02
 **/
public class RBTest {

    private static class PersonComparator implements Comparator<Person> {


        @Override
        public int compare(Person e1, Person e2) {
            return e1.getAge() - e2.getAge();
        }
    }

    private static class PersonComparator2 implements Comparator<Person> {


        @Override
        public int compare(Person e1, Person e2) {
            return e2.getAge() - e1.getAge();
        }
    }

    static void test1() {
        Integer[] arr = new Integer[]{55, 87, 56, 74, 96, 22, 62, 20, 70, 68, 90, 50};
        RBTree<Integer> rbTree = new RBTree<>();
        for (int i = 0; i < arr.length; i++) {
            rbTree.add(arr[i]);
        }
        BinaryTrees.println(rbTree);
    }

    static void test2() {
        Integer[] arr = new Integer[]{55, 87, 56, 74, 96, 22, 62, 20, 70, 68, 90, 50};
        RBTree<Integer> rbTree = new RBTree<>();
        for (int i = 0; i < arr.length; i++) {
            rbTree.add(arr[i]);
        }
        BinaryTrees.println(rbTree);

        System.out.println("=======================");

        for (int i = 0; i < arr.length; i++) {
            rbTree.remove(arr[i]);
            System.out.println("[" + arr[i] + "]");
            BinaryTrees.println(rbTree);

            System.out.println("--------------------------");
        }
    }

    public static void main(String[] args) throws Exception {
        test2();
    }
}
